<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<div id="stationQueryGrid"></div>
<div id="stationQueryToolbar">
    <div>
     <a href="javascript:void(0)"  onclick="assist.toolbar.showAddDialog()" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:'true'">
    	新增
    </a>
    <a href="javascript:void(0)"  onclick="assist.toolbar.showAssistSearchDialog();" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:'true'">
    	详情
    </a>
    <a href="javascript:void(0)" onclick="assist.toolbar.redo();" class="easyui-linkbutton" data-options="iconCls:'icon-redo',plain:true,">
    	取消
    </a>
    </div>
	<div>
	<strong>标题</strong>
	<input type="text" id="titleSearch" name="title" class="easyui-textbox" style="width:100px;">
	<strong>发送类型</strong>
	<select id="sendTypeSearch" class="easyui-combobox" name="sendTypeSearch" style="width:100px;">
	<option value="1">我所发送</option>
	<option value="2">其他发送</option>
	</select>
	<strong>发送角色</strong>
	<select id="senderSearch" name="senderSearch"  style="width:100px;"></select>
	<strong>信息状态</strong>
	<select id="infoStateSearch" name="infoStateSearch" style="width:100px;height: 24px;border-radius:5px">
	<option value="0">全部</option>
	<option value="1">生效</option>
	<option value="2">待生效</option>
	<option value="3">已删除</option>
	</select>
	<strong>是否过期</strong>
	<select id="expireSearch" name="expireSearch"  style="width:100px;height: 24px;border-radius:5px">
	<option value="0">全部</option>
	<option value="1">是</option>
	<option value="2">否</option>
	</select>
	<a href="javascript:void(0)" class="easyui-linkbutton" onclick="assist.toolbar.search();" data-options="iconCls:'icon-search',plain:true">
	查询
	</a>
	</div>    
 </div>
<div id="assistStationInfoSearchDialog" class="easyui-dialog ec-dialog" data-options="
title: '站内详细查看',
buttons: '#assistStationInfoSearchButtons',
iconCls:'icon-search',
closed: true,
onClose:assist.toolbar.resetAssistSearchForm">
	<form id="assistStationInfoSearchForm" method="post">
	     <input type="hidden" name="id"/>
		<p>
			<input type="text" name="title" class="easyui-textbox" data-options="label:'标题：',required:true"  style="width: 300px">
		</p>
		<p>
			<input type="text" name="content" class="easyui-textbox" style="width: 300px;height:150px" data-options="label:'内容：',multiline:true,required:true">
		</p>
		<p>
			<input type="text" name="sendername" class="easyui-textbox" data-options="label:'发送者：',required:true"  style="width: 300px">
		</p>
		<p>
			<input type="text" name="receivername" class="easyui-textbox" data-options="label:'发送角色：',required:true"  style="width: 300px">
		</p>
		<p>
			<input type="text" name="send_time" class="easyui-textbox" data-options="label:'发送时间：',required:true" style="width: 300px">
		</p>
		<p>
			<input type="text" name="expire_time" class="easyui-textbox" data-options="label:'过期时间：',required:true" style="width: 300px">
		</p>
		<p>
			<input type="text" name="acceptname" class="easyui-textbox" data-options="label:'接受者：',required:true" style="width: 300px">
		</p>
		<p>
			<input type="text" name="classname" class="easyui-textbox" data-options="label:'接受班级：',required:true" style="width: 300px">
		</p>
		<p>
			<input type="text" name="state" class="easyui-textbox" data-options="label:'状态：',required:true" style="width: 300px">
		</p>
	</form>
</div>
<div id="assistStationInfoSearchButtons">
    <a href="javascript:void(0)" onclick="assist.toolbar.updateCombotreeshow(id);" class="easyui-linkbutton" data-options="
	iconCls: 'icon-edit',
	plain: true">
		修改
	</a>
	<a href="javascript:void(0)" onclick="assist.toolbar.hiddenAssistSearchForm();" class="easyui-linkbutton" data-options="
	iconCls: 'icon-redo',
	plain: true">
		取消
	</a>
</div>
<div id="assistStationAddDialog" class="easyui-dialog ec-dialog" data-options="
title:'新增站内信息',
buttons:'#assistStationAddButtons',
iconCls:'icon-man',
plain:true,
closed:true,
onClose:assist.toolbar.resetAssistSearchForm()">
	<form id="assistStationAddForm" method="post">
		<p>
			<input type="text" id="titleAdd" name="titleAdd" class="easyui-textbox" data-options="label:'标题：',required:true"  style="width: 300px">
		</p>
		<p>
			<input type="text" name="content" class="easyui-textbox" style="width: 300px;height:150px" data-options="
			label:'内容：',
			multiline:true,
			required:true">
		</p>
		<p>
			<input type="text" id="appointNameAdd" name="acceptname"  class="easyui-combobox" data-options="label:'指定人员：',required:true" style="width: 300px">
		</p>
		<p>
			<input type="text" id="appointClassnameAdd" name="classname" class="easyui-combobox" data-options="label:'指定班级：',required:true" style="width: 300px">
		</p>
		<p>
			<input type="text" name="expire_time" class="easyui-datetimebox" data-options="label:'过期时间：',required:true" style="width: 300px">
		</p>
		<p>
			<select id="infoStateSearchAdd" name="infoStateSearch" class="easyui-combobox" data-options="label:'状态：',required:true" style="width: 300px">
			<option value="1">生效</option>
			<option value="2">待生效</option>
			<option value="3">已删除</option>
			</select>
		</p>
		
	</form>
</div>
<div id="assistStationAddButtons">
	<a href="javascript:void(0)" onclick="assist.toolbar.add()" class="easyui-linkbutton" data-options="
	iconCls: 'icon-add',
	plain: true">
		新增
	</a>
	<a href="javascript:void(0)" onclick="assist.toolbar.hiddenAssistSearchForm();" class="easyui-linkbutton" data-options="
	iconCls: 'icon-redo',
	plain: true">
		取消
	</a>
</div>

<div id="assistStationUpdateDialog" class="easyui-dialog ec-dialog" data-options="
title:'修改站内信息',
buttons:'#assistStationUpdateButtons',
iconCls:'icon-man',
plain:true,
closed:true,
onClose:assist.toolbar.resetAssistSearchForm()">
	<form id="assistStationUpdateForm" method="post">
	 		<input type="hidden" name="id"/>
		<p>
			<input type="text" id="title" name="title" class="easyui-textbox" data-options="label:'标题：',required:true"  style="width: 300px">
		</p>
		<p>
			<input type="text" name="content" class="easyui-textbox" style="width: 300px;height:150px" data-options="
			label:'内容：',
			multiline:true,
			required:true">
		</p>
		<p>
			<input type="text" id="appointNameUpdate" name="acceptname"  class="easyui-textbox" data-options="label:'指定人员：',required:true" style="width: 300px">
		</p>
		<p>
			<input type="text" id="appointClassnameUpdate" name="classname" class="easyui-textbox" data-options="label:'指定班级：',required:true" style="width: 300px">
		</p>
		<p>
			<input type="text" name="expire_time" class="easyui-datetimebox" data-options="label:'过期时间：',required:true" style="width: 300px">
		</p>
		<p>
			<select id="state" name="state" class="easyui-combobox" data-options="label:'状态：',required:true" style="width: 300px">
			<option value="1">生效</option>
			<option value="2">待生效</option>
			<option value="3">已删除</option>
			</select>
		</p>
		
	</form>
</div>
<div id="assistStationUpdateButtons">
	<a href="javascript:void(0)" onclick="assist.toolbar.update();" class="easyui-linkbutton" data-options="
	iconCls: 'icon-edit',
	plain: true">
		修改
	</a>
	<a href="javascript:void(0)" onclick="assist.toolbar.hiddenAssistUpdateForm();" class="easyui-linkbutton" data-options="
	iconCls: 'icon-redo',
	plain: true">
		取消
	</a>
</div>
    <script>
    var assist = {
    	init : function(){
    		assist.stationQueryGrid=$('#stationQueryGrid');
    		assist.assistStationInfoSearchForm=$('#assistStationInfoSearchForm');
    		assist.assistStationInfoSearchDialog=$('#assistStationInfoSearchDialog');
    		assist.senderSearch = $('#senderSearch');
    		assist.titleSearch = $('#titleSearch');
    		assist.sendTypeSearch = $('#sendTypeSearch');
    		assist.infoStateSearch = $('#infoStateSearch');
    		assist.expireSearch = $('#expireSearch');
    		assist.assistStationAddForm = $('#assistStationAddForm');
    		assist.assistStationAddDialog = $("#assistStationAddDialog");
    		assist.appointNameAdd= $('#appointNameAdd');
    		assist.appointClassnameAdd= $('#appointClassnameAdd');
    		assist.stateAdd = $('#stateAdd');
    		assist.titleAdd =$('#titleAdd');
    		assist.assistStationUpdateDialog = $('#assistStationUpdateDialog');
    		assist.assistStationUpdateForm = $('#assistStationUpdateForm');
    		
    		assist.senderSearch.combobox({
    			url:'<%=request.getContextPath()%>/AssistServlet?command=senderCombobox',
    			valueField:'id',    
				textField:'name',
				mode:'local',
				multiple:true,
    		});
    		
    		assist.stationQueryGrid.datagrid({
    			url:'<%=request.getContextPath()%>/AssistServlet?command=listAssistStationQuery',
    			fitColumns:true,
    			striped:true,
    			pagination:true,
    			pagiSize:10,
    			pagiList:[10,20,30,40,50],
    			pagiNumber:1,
    			toolbar:'#stationQueryToolbar',
    			columns:[[
    			          {field:'id',width:100,checkbox:true},
    			          {field:'title',title:'标题',width:100,align:'center'},
    			          {field:'sendername',title:'发送者',width:100,align:'center'},
    			          {field:'receivername',title:'发送角色',width:100,align:'center'},
    			          {field:'send_time',title:'发送时间',width:100,align:'center'},
    			          {field:'expire_time',title:'过期时间',width:100,align:'center'},
    			          {field:'state',title:'状态',width:100,align:'center',formatter:function(value,row,index){
    			        	  if(row.state==1){
    			        		  return "生效";
    			        	  }else if(row.state==2){
    			        		  return "待生效";
    			        	  }else{
    			        		  return "已删除";
    			        	  }
    			        	  }},
    			          {field:'operate',title:'操作',width:50,align:'center',formatter:assist.row.showState}
    			          ]],
    			    onDblClickRow: function(rowIndex, rowData) {
    					assist.toolbar.showAssistSearchDialog(rowData.id);
    				}
    		});
    	},
    	//按钮模块
    	toolbar:{
    		redo:function(){
    			assist.stationQueryGrid.datagrid('unselectAll');
    		},
    		showAssistSearchDialog:function(id){
    			var getData = function(v)
				{
					$.post('<%=request.getContextPath()%>/AssistServlet?command=listAssistStationMinute', {id : v}, function(data) {
						if (data) {
							assist.assistStationInfoSearchForm.form('load', {
								id:data.id,
								content: data.content,
								state: data.state,
								expire_time: data.expire_time,
								receivername: data.receivername,
								send_time: data.send_time,
								sendername: data.sendername,
								title: data.title,
								acceptname: data.acceptname,
								classname: data.classname
							});
							$('#assistStationInfoSearchDialog').dialog('open');
						} else {
							$.messager.alert('系统提示', '获取信息失败！', 'error')
						}
						$.messager.progress('close');
					}, 'json');
				}
				if (id) {
					getData(id);
				} else {
					var row = assist.stationQueryGrid.datagrid('getSelections');
					if (row.length == 1) {
						getData(row[0].id);
					} else {
						$.messager.show({
							title: '系统提示',
							msg: '请选择一行数据进行查看！',
							timeout: 3000,
							showType: 'slide'
						});	
					}
				}
    		},
    		
    		showSearAddCombotree:function(){
    			assist.appointNameAdd.combobox({
        			url:'<%=request.getContextPath()%>/AssistServlet?command=searchNameAdd',
        			valueField:'id',
        			textField:'name',
        			mode:'local',
        			multiple:true
        		});
    			assist.appointClassnameAdd.combobox({
    				url:'<%=request.getContextPath()%>/AssistServlet?command=appointClassnameAdd',
        			valueField:'id',
        			textField:'name',
        			mode:'local',
        			multiple:true
    			});
    			assist.stateAdd.combobox({
    				url:'<%=request.getContextPath()%>/AssistServlet?command=stateAdd',
        			valueField:'id',
        			textField:'state',
        			mode:'local',
        			multiple:true
    			});
    		},
    		
    		showAddDialog:function(){
    			assist.toolbar.showSearAddCombotree();
    			assist.assistStationAddDialog.dialog('open');
    			assist.titleAdd.focus();
    		},
    		
    		add:function(){
    			if(assist.assistStationAddForm.form('validate')){
    				$.messager.progress({
    					text:'正在处理...'
    				}); 
    				$.post('<%=request.getContextPath()%>/AssistServlet?command=assistInfoAdd',assist.assistStationAddForm.serialize(),function(data){
    					if(data==1){
    						$.messager.show({
    							title: '系统提示',
								msg: '新增成功！',
								timeout: 3000,
								showType: 'slide'
    						});
    					assist.assistStationAddForm.form('reset');
    					assist.stationQueryGrid.datagrid('reload');
    					}else {
    						$.messager.alert('系统提示', '新增失败！', 'error')
    					}
    					$.messager.progress('close');
    					assist.assistStationAddDialog.dialog('close');
    					
    				});
    			}
    		},
    		
    		updateCombotreeshow:function(){
    			assist.assistStationInfoSearchDialog.dialog('close');
					$.post('<%=request.getContextPath()%>/AssistServlet?command=listUpdateMinute', assist.assistStationInfoSearchForm.serialize(), function(data) {
						if (data) {
							assist.assistStationUpdateForm.form('load', {
								id:data.id,
								title:data.title,
								content:data.content,
								acceptname:data.acceptname,
								classname:data.classname,
								expire_time:data.expire_time,
								state:data.state
							});
							$('#assistStationUpdateDialog').dialog('open');
						} else {
							$.messager.alert('系统提示', '获取信息失败！', 'error')
						}
						$.messager.progress('close');
					}, 'json');
    		},
    		 
    		
    		 
    		update:function(){
    			if(assist.assistStationUpdateForm.form('validate')){
    			    $.messager.progress({
    					text:'正在处理...'
    				});
    				$.post('<%=request.getContextPath()%>/AssistServlet?command=assistInfoUpdate',assist.assistStationUpdateForm.serialize(),function(data){
    					if(data){
    						$.messager.show({
    							title: '系统提示',
								msg: '修改成功！',
								timeout: 3000,
								showType: 'slide'
    						});
    					assist.assistStationUpdateForm.form('reset');
    					assist.stationQueryGrid.datagrid('reload');
    					}else {
    						$.messager.alert('系统提示', '修改失败！', 'error')
    					}
    					$.messager.progress('close');
    					assist.assistStationUpdateDialog.dialog('close');
    				});
    			}
    		},
    		
    		hiddenAssistUpdateForm:function(){
    			assist.assistStationUpdateDialog.dialog('close');
    		},
    		 
    		hiddenAssistSearchForm:function(){
    			$('#assistStationInfoSearchDialog').dialog('close');
    			$('#assistStationAddDialog').dialog('close');
    			assist.toolbar.resetAssistSearchForm();
    		},
    		
    		resetAssistSearchForm:function(){
    			assist.assistStationInfoSearchForm.form('reset');
    			assist.assistStationAddForm.form('reset');
    			
    		},
    		
    		search:function(){
    			assist.stationQueryGrid.datagrid('load',{
    				titleSearch:assist.titleSearch.val(),
    				sendTypeSearch:assist.sendTypeSearch.combobox('getValue'),
    				senderSearch:assist.senderSearch.combobox('getValue'),
    				infoStateSearch:assist.infoStateSearch.val(),
    				expireSearch:assist.expireSearch.val(),
    			});
    		},
    	},
    	//操作，，模块
    	row:{
    		showState:function(value, row, index){
    			var id = row.id;
    			var state = row.state;
    			value:state;
    			if(state == 1) {
    				value = '删除';
    			}else if(state == 2) {
    				value = '生效|删除';
    			} else{
    				value = ' ';
    			}
    			
    			var operations = [];
    			operations.push('<a href="javascript:viod(0)" onclick="assist.row.updateState(\''+id+'\',\''+state+'\',\''+index+'\')">'+value+'</a>');
    			return operations.join('');
    		},
    		updateState:function(id, value, index){
    			$.messager.confirm('系统提示','确定要操作吗？',function(result){
    				if(result){
    					$.post('<%=request.getContextPath()%>/AssistServlet?command=updateState',{id:id, value:value},function(data){
    						if(data){
    							$.messager.show({
    								title:'系统提示',
    								msg:'状态操作成功！',
    								timeout:3000,
    								showType:'slide',
    							});
    							assist.stationQueryGrid.datagrid('reload');
    						}else{
    							$.messager.alert('系统提示','状态操作错误！','error');
    						}
    					},"json");
    				}
    			});
    		},
    	}
    };
    $(function(){
    	assist.init();
    });
   </script>